const mongoose = require('mongoose');

const DB_URL = 'mongodb://localhost:27017/maobing';

// mongoose.connect(DB_URL);

// mongoose.connection.on('connected', () => {
//   console.log('mongoose connection open on:' + DB_URL);
// });

// mongoose.connection.on('error', (err) => {
//   console.log('mongoose connection error:' + err);
// });

// mongoose.connection.on('disconnected', () => {
//   console.log('mongoose connection disconnected');
// });

mongoose.connect(
  DB_URL,
  { useNewUrlParser: true, useUnifiedTopology: true },
  (err) => {
    if (err) {
      console.log('err: ' + err);
    } else {
      console.log('[Mongoose] database connected success!');
    }
  }
);

module.exports = mongoose;
